/**
 * 2013 2013-5-8
 */
package com.surfilter.dp.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

/**
 *
 */
public class PropertyFileManager {
	private static Properties prop;
	static {
		prop = new Properties();
		try {
			prop.load(PropertyFileManager.class.getResourceAsStream("/config/properties/source.properties"));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public static String getProp(String key){
		return prop.getProperty(key);
	}
	
	public static void setProp(String key,String value){
		prop.setProperty(key, value);
	}
	
	public static void save(){
		try {
			prop.store(new FileOutputStream(PropertyFileManager.class.getResource("/config/properties/source.properties").getFile()), "save");
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	/**
	 * @return
	 */
	public static boolean validateProps(){
		if(validateProp("jdbcUrl") && validateProp("user")&& validateProp("password")  && validateProp("project_path")){
			return true;
		}
		return false;
	}
	public static void main(String[] args) {
		System.out.println(validateProps());
	}
	
	private static boolean validateProp(String key){
		String value = prop.getProperty(key);
		if(value == null || "".equals(value.trim())){
			return false;
		}
		return true;
	}

}
